<?php


require_once ("db_common.php");
require_once ("XMLUtils.php");
class Turnover
{

    function Init($turnoverid)
    {
        $sql = "select turnover_id,turnover_remark,turnover_from,turnover_to,turnover_time,turnover_money,turnover_type,category_id
         from turnover where turnover_id = '$turnoverid'";

        if ($query = mysql_query($sql))
        {
            $row = mysql_fetch_array($query);
            //print_r($row);
            $this->id = $row['turnover_id'];
            $this->remark = $row['turnover_remark'];
            $this->from = $row['turnover_from'];
            $this->to = $row['turnover_to'];
            $this->time = $row['turnover_time'];
            $this->money = $row['turnover_money'];
            $this->type = $row['turnover_type'];
            $this->catid = $row['category_id'];
        } else
        {
            echo "turnoverid = " + $turnoverid;
            output_mysqlerror();
        }
    }

    function Update()
    {
        if ($this->id)
        {
            $sql = "update turnover set turnover_remark = '$this->remark',turnover_from = '$this->from'
            ,turnover_to = '$this->to',turnover_time = '$this->time',turnover_money = '$this->money'
            ,category_id = '$this->catid' where turnover_id = '$this->id'";
            if ($query = mysql_query($sql))
            {

            } else
            {
                echo "id = " + $this->id;
                output_mysqlerror();
            }
        } else
        {
            echo "Turnoverid is empty In Turnover::Update";
        }
    }

    function GetXMLNode($doc)
    {
        $s = $doc->createElement("turnover");
        // $r->appendChild($s);

        AppendNewTextNode($doc, "remark", $this->remark, $s);
        AppendNewTextNode($doc, "id", $this->id, $s);
        AppendNewTextNode($doc, "time", $this->time, $s);
        AppendNewTextNode($doc, "money", $this->money, $s);
        AppendNewTextNode($doc, "type", $this->type, $s);
        
        if($this->type != 0)//支出没有to
        {
            AppendNewTextNode($doc, "to", $this->to, $s);
        }
        if($this->type != 1)//收入没有from
        {
            AppendNewTextNode($doc, "from", $this->from, $s);
        }

        if($this->type != 2)//转账没有catid
        {
            AppendNewTextNode($doc, "catid", $this->catid, $s);
        }
        
        return $s;
    }

    var $id;
    var $money;
    var $remark;
    var $from;
    var $to;
    var $time;
    var $type;
    var $catid;
}

?>